{%extends 'layout.html'%}
{%block body%}
<link type='text/css' rel='stylesheet' href="{{url_for('static', filename='css/pagination.css') }}"/>
<script type='text/javascript' src="{{url_for('static', filename='js/jquery.pagination.js') }}"></script>
<script type='text/javascript' src="{{url_for('static', filename='js/invite-dlg.js') }}"></script>
<script type='text/javascript' src="{{url_for('static', filename='js/jquery.watermarkinput.js') }}"></script>
<script type='text/javascript' src="{{url_for('static', filename='js/jquery.form.js') }}"></script>
<script>
$(function(){
	activity_id = {{activity.id}};
	$('#invite-dlg').dialog('option', 'buttons', {'邀请': function(){
 		var candidates_str = get_candidates_str();
    	$('#invite-list').attr('value', candidates_str);   	
    	$('#invite-form').submit();
 	}});	
    $('#rsvp').click(function(){
    	$('#rsvp-options').toggleClass('hide');
    	return false;
    });
    $('form#rsvp-form').ajaxForm({
    	success : function(response){
    		$('#rsvp').html(response).click();
    	},
    });
    $('#reason').Watermark('给个理由');
})
</script>
<div id='invite-dlg'>
	<div id='invite-dlg-candidates'>		
	</div>
	<form action='/activity/invite/{{activity.id}}' method='post' id='invite-form'>
		{{csrf_token()}}
		<input type='hidden' name='invite-list' id='invite-list'/>
	</form>
	
</div>
<div class='left-panel'>
	<div class='mid-panel ui-widget-content'>
		<img id='cover' src='{{activity.image}}' class='act-img'/>	
	</div>
	<div class='bottom-panel'>
		{%if activity.attended_invites.count() > 0%}
			<div>
				<h5>
					{{activity.attended_invites.count()}}&nbsp;参加:
					<a class="float-right" href="/activity/invite/{{activity.id}}">查看全部&nbsp;&nbsp;</a>
				 </h5>	
				{%for invite in activity.attended_invites[:2]%}
			    	<div class='small-user-block'><img src='{{invite.participant.portrait}}'><p>{{invite.participant.name}}</p></div>
			    {%endfor%}				
			</div>
			<hr class="space"/>
		{%endif%}
		{%if activity.maybe_attend_invites.count() > 0%}
			<div>
				<h5>{{activity.maybe_attend_invites.count()}}&nbsp;可能参加:</h5>
				{%for invite in activity.maybe_attend_invites[:2]%}
					<div class='small-user-block'><img src='{{invite.participant.portrait}}'><p>{{invite.participant.name}}</p></div>
				{%endfor%}
			</div>
			<hr class="space"/>
		{%endif%}
		{%if activity.declined_invites.count() > 0%}
			<div>
			    <h5>{{activity.declined_invites.count()}}&nbsp;不参加:</h5>
			    {%for invite in activity.declined_invites[:2]%}
			    	<div class='small-user-block'><img src='{{invite.participant.portrait}}'><p>{{invite.participant.name}}</p></div>
			    {%endfor%}
			</div>
			<hr class="space"/>
		{%endif%}
		{%if activity.unhandled_invites.count() > 0%}
			<div>
			    <h5>{{activity.unhandled_invites.count()}}&nbsp;尚未表态:</h5>
			    {%for invite in activity.unhandled_invites[:2]%}
			    	<div class='small-user-block'><img src='{{invite.participant.portrait}}'><p>{{invite.participant.name}}</p></div>
			    {%endfor%}
			</div>
		{%endif%}
	</div>
</div>
<div class="right-panel ">
	<div class='ui-widget-content detail-panel'>
		<p>
			{%if privilege['edit']%}<a href='/activity/edit/{{activity.id}}'>编辑活动</a>{%endif%}
			{%if privilege['cancel']%} <a href='/activity/cancel/{{activity.id}}'>取消活动</a>{%endif%}
			{%if privilege['invite']%}<a id='invite' href='/'>邀请好友</a>{%endif%}
		</p> 
		<h4>{{activity.title}}</h4>
		<p>
			{{activity.is_public_display()}} · 
			{{activity.activity_type}} · 
			{{activity.state}} · 
			{%if privilege['rsvp']%}
			<a href='/activity/rsvp/{{activity.id}}' id='rsvp'>{{user_state}}</a> · 
			{%endif%}
			分享
		</p>
		<div class='hide ui-widget-header' id='rsvp-options'>
			<form action='/activity/rsvp/{{activity.id}}' method='post' id='rsvp-form'>
				{{csrf_token()}}
				<input type='text' name='reason' id='reason'/>
				<input type='submit' name='attend' value='参加' class='button'/>
				<input type='submit' name='maybe' value='可能参加' class='button'/>
				<input type='submit' name='decline' value='不参加' class='button'/>
			</form>
		</div>
		<hr class='space'/>
		<hr class='space'/>
		<table>       
			<tbody>
			  <tr>
			  	<th>创建者</th>
			  	<td>{{activity.creator}}</td>
			  </tr>
		  	  <tr><td colspan=2><hr/></td></tr>	
			  <tr>
			    <th>开始时间</th>
			    <td>
			    {%if activity.start_time%}
			      {{activity.start_time}}
			    {%else%}
			      <a href="/activity/poll/{{activity.id}}">投票</a>
			    {%endif%}
			    </td>
			  </tr>
			  <tr><td colspan=2><hr/></td></tr>
			  {%if activity.end_time%}
			  <tr>
			  	<th>结束时间:</th>
			  	<td>{{activity.end_time}}</td>
			  </tr>
		  	  <tr><td colspan=2><hr/></td></tr>
			  {%endif%}
			  <tr><th>活动地点</th> <td>{{activity.activity_place}}</td></tr>
			  <tr><td colspan=2><hr/></td></tr>
			  {%if activity.description%}
			  <tr><th>活动介绍</th><td>{{activity.description}}</td></tr>
			  <tr><td colspan=2><hr/></td></tr>
			  {%endif%}	
			</tbody>
		</table>
<!-- 		<form method="post" action="/activity/post/{{activity.id}}/" class="span-15 last discuss-box">
		  <label>讨论：</label>
		  <textarea cols="70" rows="6" name="content" class="span-15 last"></textarea>
		  <div class="float-right"><input type="submit" value="发布"/></div>
		</form> -->
		
		<div class="span-15 last" id="story-info-tabs-1">	  
		{%for post in activity.get_posts%}	
		  <div class="span-15 last"> 
		    <div class="span-2">
		      <div class="person-thumb">
		        <img src="{{post.post_by.profile.portrait.url}}" class="portrait"/>          
		      </div>
		    </div>
		    <div class="span-13 last">
		      <p>
		        <a href="/user/{{post.post_by.id}}/">{{post.post_by.profile.real_name}}</a>:
		        {{post.content}}
		      </p>
		      
		      <div>{{post.post_date}}</div>
		      
		    </div>
		  </div>
		  <hr class="space"/>
		  <hr/>
		{%endfor%}	
		</div>
	</div>
</div>
{%endblock%}